const express = require('express');
const router = express.Router();
const data = [];
for(let i = 1; i < 51; i++)
    data.push({
        id: `${i}`,
        sapTransferOrderCode: 'SAPDB201909090001',
        sapDeliveryCode: 'SAPJH201909090001',
        itemCount: 10,
        totalAmount: 999,
        amount: 888,
        partSaleOrderId: '1',
        partSaleOrderCode: 'XS201909090001',
        partOrderTypeName: '紧急订单',
        transportType: 1,
        submitDate: '2019-09-04T02:37:44.918Z',
        code: 'JH201909090001',
        dealerCode: '10145',
        currency: 1,
        submitTime: '2019-09-04T02:37:44.918Z',
        totalQuantity: 10,
        orderTotalAmount: 998,
        requiredArrivedDate: '2019-09-04T02:37:44.918Z',
        amountMeetFullRate: 0.5,
        details: [
            {
                deliveryOrderId: '1',
                sapTransferOrderCode: 'SAPDB201909090001',
                sapDeliveryCode: 'SAPJH201909090001',
                partSaleOrderCode: 'XS201909090001',
                partId: '1',
                partCode: 'partCode1',
                partName: 'partName1',
                oldPartId: '2',
                oldPartCode: 'partCode2',
                oldPartName: 'partName2',
                price: 100,
                deliveryQuantity: 3,
                totalAmount: 200
            },
            {
                deliveryOrderId: '2',
                sapTransferOrderCode: 'SAPDB201909090002',
                sapDeliveryCode: 'SAPJH201909090002',
                partSaleOrderCode: 'XS201909090002',
                partId: '2',
                partCode: 'partCode2',
                partName: 'partName2',
                oldPartId: '1',
                oldPartCode: 'partCode1',
                oldPartName: 'partName1',
                price: 100,
                deliveryQuantity: 3,
                totalAmount: 200
            },
            {
                deliveryOrderId: '3',
                sapTransferOrderCode: 'SAPDB201909090003',
                sapDeliveryCode: 'SAPJH201909090003',
                partSaleOrderCode: 'XS201909090003',
                partId: '3',
                partCode: 'partCode3',
                partName: 'partName3',
                oldPartId: '4',
                oldPartCode: 'partCode4',
                oldPartName: 'partName4',
                price: 100,
                deliveryQuantity: 3,
                totalAmount: 200
            }
        ]
    });
router.get('/forPicking', (req, res) => {
    const {pageIndex, pageSize} = req.query;
    res.json({
        message: 'ok',
        payload: {
            content: data,
            pageIndex: parseInt(pageIndex, 10),
            pageSize: parseInt(pageSize, 10),
            totalElements: 50
        }
    });
});

/**
 * @param {Object} options
 * @param {} options.dealerId 总代Id
 * @param {} options.brandId 品牌Id
 * @param {} options.sapDeliveryCode SAP交货单号
 * @param {} options.sapTransferOrderCode SAP备件调拨单号
 * @param {} options.partSaleOrderCode 备件销售订单编号
 * @param {} options.status 价格条款  1-备货中  2-已发货  3-发货过账  -1-作废
 * @param {} options.pageSize 每页数据量
 * @param {} options.pageIndex 指定页
 * @param {} options.sortField 排序字段
 * @param {} options.isDesc 倒序排列
 * @throws {Error}
 * @return {Promise}
 */
router.get('/', async(req, res, next) => {
    const options = {
        dealerId: req.query.dealerId,
        brandId: req.query.brandId,
        sapDeliveryCode: req.query.sapDeliveryCode,
        sapTransferOrderCode: req.query.sapTransferOrderCode,
        partSaleOrderCode: req.query.partSaleOrderCode,
        status: req.query.status,
        pageSize: req.query.pageSize,
        pageIndex: req.query.pageIndex,
        sortField: req.query.sortField,
        isDesc: req.query.isDesc
    };
    const data = {
        message: 'message',
        payload: {
            content: [
                {
                    id: 'id177',
                    dealerCode: 'dealerCode178',
                    dealerName: 'dealerName179',
                    sapDeliveryCode: 'sapDeliveryCode180',
                    sapTransferOrderCode: 'sapTransferOrderCode181',
                    partSaleOrderCode: 'partSaleOrderCode182',
                    status: 1,
                    remark: 'remark',
                    rowVersion: 'rowVersion',
                    options: [
                        'update',
                        'close',
                    ]
                },
                {
                    id: 'id183',
                    dealerCode: 'dealerCode184',
                    dealerName: 'dealerName185',
                    sapDeliveryCode: 'sapDeliveryCode186',
                    sapTransferOrderCode: 'sapTransferOrderCode187',
                    partSaleOrderCode: 'partSaleOrderCode188',
                    status: 1,
                    remark: 'remark',
                    rowVersion: 'rowVersion',
                    options: [
                        'update',
                        'close',
                    ]
                }
            ],
            pageIndex: null,
            pageSize: null,
            sort: null,
            totalElements: 50,
            totalPages: null
        }
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.sapDeliveryCode SAP交货单号
 * @param {} options.pageSize 每页数据量
 * @param {} options.pageIndex 指定页
 * @param {} options.sortField 排序字段
 * @param {} options.isDesc 倒序排列
 * @throws {Error}
 * @return {Promise}
 */
router.get('/forSAP', async(req, res, next) => {
    const options = {
        sapDeliveryCode: req.query.sapDeliveryCode,
        pageSize: req.query.pageSize,
        pageIndex: req.query.pageIndex,
        sortField: req.query.sortField,
        isDesc: req.query.isDesc
    };
    const data = {
        message: 'message',
        payload: {
            content: [
                {
                    id: 'id189',
                    dealerCode: 'dealerCode190',
                    dealerName: 'dealerName191',
                    sapDeliveryCode: 'sapDeliveryCode192',
                    sapTransferOrderCode: 'sapTransferOrderCode193',
                    partSaleOrderCode: 'partSaleOrderCode194',
                    status: 1,
                    remark: 'remark',
                    rowVersion: 'rowVersion',
                    options: [
                        'update',
                        'close',
                    ]
                },
                {
                    id: 'id195',
                    dealerCode: 'dealerCode196',
                    dealerName: 'dealerName197',
                    sapDeliveryCode: 'sapDeliveryCode198',
                    sapTransferOrderCode: 'sapTransferOrderCode199',
                    partSaleOrderCode: 'partSaleOrderCode200',
                    status: 1,
                    remark: 'remark',
                    rowVersion: 'rowVersion',
                    options: [
                        'update',
                        'close',
                    ]
                }
            ],
            pageIndex: null,
            pageSize: null,
            sort: null,
            totalElements: 50,
            totalPages: null
        }
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.id id
 * @throws {Error}
 * @return {Promise}
 */
router.get('/:id', async(req, res, next) => {
    const options = {
        id: req.params.id
    };
    const data = {
        message: 'message',
        payload: {
            id: 'id201',
            dealerCode: 'dealerCode202',
            dealerName: 'dealerName203',
            sapDeliveryCode: 'sapDeliveryCode204',
            sapTransferOrderCode: 'sapTransferOrderCode205',
            partSaleOrderCode: 'partSaleOrderCode206',
            status: 1,
            currency: 1,
            transportType: 1,
            remark: 'remark',
            rowVersion: 'rowVersion',
            options: [
                'update',
                'close',
            ],
            details: [
                {
                    id: 'id207',
                    partId: 'partId208',
                    partCode: 'partCode209',
                    partName: 'partName210',
                    partDescription: 'partDescription',
                    oldPartId: 'oldPartId211',
                    oldPartCode: 'oldPartCode212',
                    oldPartName: 'oldPartName213',
                    deliveryQuantity: 1,
                    price: 1,
                    totalAmount: 1
                },
                {
                    id: 'id214',
                    partId: 'partId215',
                    partCode: 'partCode216',
                    partName: 'partName217',
                    partDescription: 'partDescription',
                    oldPartId: 'oldPartId218',
                    oldPartCode: 'oldPartCode219',
                    oldPartName: 'oldPartName220',
                    deliveryQuantity: 1,
                    price: 1,
                    totalAmount: 1
                }
            ]
        }
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.id Id
 * @throws {Error}
 * @return {Promise}
 */
router.put('/:id', async(req, res, next) => {
    const options = {
        id: req.params.id
    };
    const data = {
        message: 'message'
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.id Id
 * @throws {Error}
 * @return {Promise}
 */
router.put('/:id/close', async(req, res, next) => {
    const options = {
        id: req.params.id
    };
    const data = {
        message: 'message'
    };
    res.json(data);
});
/**
 * @param {Object} options
 * @param {} options.dealerId 总代Id
 * @param {} options.brandId 品牌Id
 * @param {} options.sapDeliveryCode SAP交货单号
 * @param {} options.sapTransferOrderCode SAP备件调拨单号
 * @param {} options.partSaleOrderCode 备件销售订单编号
 * @param {} options.status 价格条款  1-备货中  2-已发货  3-发货过账  -1-作废
 * @throws {Error}
 * @return {Promise}
 */

router.get('/export', async(req, res, next) => {
    const options = {
        dealerId: req.query.dealerId,
        brandId: req.query.brandId,
        sapDeliveryCode: req.query.sapDeliveryCode,
        sapTransferOrderCode: req.query.sapTransferOrderCode,
        partSaleOrderCode: req.query.partSaleOrderCode,
        status: req.query.status
    };
    const data = {
        message: 'message',
        payload: 'payload'
    };
    res.json(data);
});
module.exports = router;
